using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Specialized;

namespace Axe.Logging
{
    public class LogReplicator : ILogger, IDisposable
    {
        private List<ILogger> m_ReplicationTargets = new List<ILogger>();

        /// <summary>
        /// Gets the replication targets.
        /// </summary>
        /// <value>The replication targets.</value>
        public ICollection<ILogger> ReplicationTargets
        {
            get
            {
                return m_ReplicationTargets;
            }
        }


        /// <summary>
        /// Initializes a new instance of the <see cref="LogReplicator"/> class.
        /// </summary>
        /// <param name="loggers">The loggers.</param>
        public LogReplicator(params ILogger[] loggers)
        {
            m_ReplicationTargets.AddRange(loggers);
        }

        #region ILogger Members

        public void Add(LogEntry entry)
        {
            foreach(ILogger logger in m_ReplicationTargets)
            {
                logger.Add(entry);
            }
        }

        #endregion

        #region IDisposable Members

        public void Dispose()
        {
            foreach(ILogger logger in m_ReplicationTargets)
            {
                IDisposable disposableLogger = logger as IDisposable;

                if(disposableLogger != null)
                    disposableLogger.Dispose();
            }
        }

        #endregion

        #region ILogger Members

        public bool Initialize(NameValueCollection props)
        {
            return true;
        }

        #endregion
    }
}
